import rospy
from std_msgs.msg import Float32

def publish_float():
    pub = rospy.Publisher('/float_topic', Float32, queue_size=10)
    rospy.init_node('float_publisher', anonymous=True)
    rate = rospy.Rate(1)  # 设置发布频率为1Hz

    while not rospy.is_shutdown():
        float_data = Float32()
        float_data.data = 3.14  # 这里可以替换成你想要发布的任何float数值
        pub.publish(float_data)
        rate.sleep()

if __name__ == '__main__':
    try:
        publish_float()
    except rospy.ROSInterruptException:
        pass